<template>
  <div>
    <div class="nav">
      <div class="nav-total-image">
        <el-image :src="require('../../assets/ok.png')" class="nav-total-image-total"/>
      </div>
      <div class="">
        <el-menu class="nav-item" router>
          <el-menu-item @click="shouYe" index="/index/dashboard/examination" :class="flag === 1 ? 'border-bottom' : ''">
            首页(考试)
          </el-menu-item>
          <el-menu-item @click="shiJuan" index="/index/dashboard/papers" :class="flag === 2 ? 'border-bottom' : ''">
            考试记录
          </el-menu-item>
          <el-menu-item>
            <el-image class="nav-image" @click="look" :class="flag === 3 ? 'border-bottom' : ''" :src="src"/>
            <!--                      :src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1607675228780&di=c1beabb443fc7e45f88d26fe0ea76602&imgtype=0&src=http%3A%2F%2Fa4.att.hudong.com%2F27%2F67%2F01300000921826141299672233506.jpg"/>-->

          </el-menu-item>
        </el-menu>
      </div>
    </div>
    <div class="dcdcd" :class="looks=== 1? 'block': 'none'">
      <el-menu>
        <el-menu-item index="1-1" @click="mine">个人信息</el-menu-item>
        <el-menu-item index="1-2" @click="goOut">退出</el-menu-item>
      </el-menu>
    </div>
  </div>

</template>

<script>
  import {UseToken, GetClazz} from "../../api/index"

  export default {
    name: "total",
    data() {
      return {
        src: this.$store.state.user.image,
        flag: 1,
        //显示与隐藏
        looks: 0,
      }
    },
    methods: {
      shouYe() {//首页
        this.flag = 1;
        // this.$emit("number", this.flag)
      },
      shiJuan() {//试卷
        this.flag = 2;
        // this.$emit("number", this.flag)
      },
      goOut() {//退出
        localStorage.removeItem("party_user");
        // this.$store.dispatch("setUser", "");
        this.$router.replace("/index/login");
      },
      mine() {//我的
        this.$router.replace('/index/dashboard/mine');
      },
      async getUseToken() {
        await UseToken({}).then((res) => {
          // console.log(res);
          this.$store.dispatch("setUser", res.data.user)
        }).catch((err) => {
          console.log(err);
        });
        // console.log(this.$store.state.user);
        this.getClazz(this.$store.state.user.classId)
      },
      look() {
        this.flag = 3;
        if (this.looks === 1) {
          this.looks = 0
        } else {
          this.looks = 1
        }
      },
      async getClazz(clazzId) {
        await GetClazz({clazzId: clazzId}).then((res) => {
          // console.log(res.data.clazz);
          this.$store.dispatch("setClazz",res.data.clazz)
        }).catch((err) => {
          console.log(err);
        })
      }
    },
    watch: {
      flag: {
        handler(newValue, oldValue) {
          return newValue
        }
      }
    },
    created() {
      this.getUseToken()
    },
  }
</script>

<style scoped>
  .el-menu {
    border-right: 0;
  }

  .nav {
    width: 100%;
    border-bottom: 1px solid #e6e6e6;
    margin-bottom: 25px;
    display: flex;
    flex-direction: row;
    height: 56px;
  }

  .nav-total-image {
    width: 90%;
  }

  .nav-total-image-total {
    width: 170px;
    height: 56px;
  }

  .nav-item {
    display: flex;
    flex-direction: row;
    font-size: 16px;
    width: 15%;
  }

  .nav-item > div {
    width: 25%;
    line-height: 60px;
    text-align: center;
  }

  .nav-image {
    width: 40px;
    height: 40px;
    border-radius: 10em;
    margin-top: 10px;
    text-align: center;
    /*margin-left: 30%;*/
  }

  .nav-me {
    display: block;
    width: 120%;
  }

  .nav-item > div:hover {
    cursor: pointer;
    color: #001135;
  }

  /*.border-bottom {*/
  /*  border-bottom: 1px solid #409eff;*/
  /*}*/

  .dcdcd {
    position: fixed;
    top: 58px;
    right: 2px;
    z-index: 25;
  }

  .block {
    display: block;
  }

  .none {
    display: none;
  }


</style>
